package com.flyway.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

//@Configuration
//@EnableSwagger2
public class SwaggerGroupConfiguration {
    @Value("${swagger.enable}")
    private boolean enable;

    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("测试接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.flyway.controller.test"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean(value = "groupRestApi")
    public Docket groupRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(groupApiInfo())
                .groupName("用户接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.flyway.controller.user"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo groupApiInfo() {
        return new ApiInfoBuilder()
                .title("分组Api")
                .description("swagger-bootstrap-ui-demo RESTful APIs")
                .termsOfServiceUrl("http://www.group.com/")
                .contact("group@qq.com")
                .version("1.0")
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("flyway-first-swagger-ui")
                .description("swagger-bootstrap-ui")
                .termsOfServiceUrl("https://www.baidu.com")
                .contact("秋")
                .version("1.0")
                .build();
    }
}